package com.ruoyi.web.controller.stock;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.StockBase;
import com.ruoyi.system.service.IStockBaseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 每日基础数据Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/stock/base")
public class StockBaseController extends BaseController
{
    @Autowired
    private IStockBaseService stockBaseService;

    /**
     * 查询每日基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('stock:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockBase stockBase)
    {
        startPage();
        List<StockBase> list = stockBaseService.selectStockBaseList(stockBase);
        return getDataTable(list);
    }

    /**
     * 导出每日基础数据列表
     */
    @PreAuthorize("@ss.hasPermi('stock:base:export')")
    @Log(title = "每日基础数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockBase stockBase)
    {
        List<StockBase> list = stockBaseService.selectStockBaseList(stockBase);
        ExcelUtil<StockBase> util = new ExcelUtil<StockBase>(StockBase.class);
        util.exportExcel(response, list, "每日基础数据数据");
    }

    /**
     * 获取每日基础数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('stock:base:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(stockBaseService.selectStockBaseByRecordId(recordId));
    }

    /**
     * 新增每日基础数据
     */
    @PreAuthorize("@ss.hasPermi('stock:base:add')")
    @Log(title = "每日基础数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockBase stockBase)
    {
        return toAjax(stockBaseService.insertStockBase(stockBase));
    }

    /**
     * 修改每日基础数据
     */
    @PreAuthorize("@ss.hasPermi('stock:base:edit')")
    @Log(title = "每日基础数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockBase stockBase)
    {
        return toAjax(stockBaseService.updateStockBase(stockBase));
    }

    /**
     * 删除每日基础数据
     */
    @PreAuthorize("@ss.hasPermi('stock:base:remove')")
    @Log(title = "每日基础数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(stockBaseService.deleteStockBaseByRecordIds(recordIds));
    }
}
